<?php
namespace Util;
class LogUtil
{
    /**
     * 记录日志
     * @param $file_name
     * @param $data
     * @return int
     */
    public static function log($file_name, $data)
    {
        $log_path = sys_get_temp_dir() . '/logs';
        if (!is_readable($log_path)) {
            is_file($log_path) or mkdir($log_path, 0777);
        }
        $log_file = $log_path . '/log-' . $file_name .'-' . date('Ymd') . '.txt';
        $data = array(
            'time' => date("Y-m-d H:i:s"),
            'info' => $data
        );
        $log_string = json_encode($data) . PHP_EOL;
        return file_put_contents($log_file, $log_string, FILE_APPEND);
    }
}